package data;

import java.util.ArrayList;
import java.util.List;

import com.EntityName;
import com.google.appengine.api.datastore.Entity;

public class Package  extends AbstractData {
	private long id = -1;
	private  long hotelId;
	private String Name;
	private String shortName;
	private long lengthOfStay;
	private String Description;
	private List<PackagePrice> packagepriceList;
	private String packagepriceListString;
	private boolean status;
	private boolean avaliable;
	
	public Package(){
		status = true;
		avaliable = true;		
	}
	
public Package(long id){
		this.id=id;
		this.status = true;
		this.avaliable = true;
	}
	
	public long getId() {
		return id;
	}
	
	public void setId(long id) {
		this.id = id;
	}

	public long getHotelId() {
		return hotelId;
	}

	public void setHotelId(long hotelId) {
		this.hotelId = hotelId;
	}

	public String getName() {
		return Name;
	}

	public void setName(String name) {
		Name = name;
	}

	public String getShortName() {
		return shortName;
	}

	public void setShortName(String shortName) {
		this.shortName = shortName;
	}

	public long getLengthOfStay() {
		return lengthOfStay;
	}

	public void setLengthOfStay(long lengthOfStay) {
		this.lengthOfStay = lengthOfStay;
	}

	public String getDescription() {
		return Description;
	}

	public void setDescription(String description) {
		Description = description;
	}

	public List<PackagePrice> getPackagepriceList() {
		if ((packagepriceList == null || packagepriceList.size() == 0) && !(packagepriceListString == null && packagepriceListString.isEmpty())) {
			String[] idOfList = SplitList(packagepriceListString);
			List<PackagePrice> list = new ArrayList<PackagePrice>();
			for (String id : idOfList) {
				PackagePrice a = new PackagePrice(Long.parseLong(id));
				list.add(a);
			}
			for(PackagePrice a : list)
				a.LoadData();
			packagepriceList = list;
		}
		return packagepriceList;
	}

	public void setPackagepriceList(List<PackagePrice> packagepriceList) {
		this.packagepriceListString = CombineList(packagepriceList);
		this.packagepriceList = packagepriceList;
	}

	
	public void setPackagepriceListString(String packagepriceListString) {
		this.packagepriceListString = packagepriceListString;
	}

	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	public boolean isAvaliable() {
		return avaliable;
	}

	public void setAvaliable(boolean avaliable) {
		this.avaliable = avaliable;
	}

	@Override
	public Entity getEntity() {
		Entity item;
		if(this.key == null)
			item = new Entity(EntityName.Package);
		else
			item = new Entity(this.key);
		
		item.setProperty("hotelId", this.hotelId);
		item.setProperty("Name", this.Name);
		item.setProperty("shortName", this.shortName);
		item.setProperty("lengthOfStay", this.lengthOfStay);
		item.setProperty("Description", this.Description);
		item.setProperty("packagepriceList", this.packagepriceListString);
		item.setProperty("status", this.status);
		item.setProperty("avaliable", this.avaliable);
		return item;
	}
	@Override
	public void setEntity(Entity entity) {
		this.id = entity.getKey().getId();
		this.hotelId = (Long) entity.getProperty("hotelId");
		this.Name = (String) entity.getProperty("Name");
		this.shortName = (String) entity.getProperty("shortName");
		this.lengthOfStay = (Long) entity.getProperty("lengthOfStay");
		this.Description = (String) entity.getProperty("Description");
		this.packagepriceListString = (String) entity.getProperty("packagepriceList");
		this.status = (Boolean) entity.getProperty("status");
		this.avaliable = (Boolean) entity.getProperty("avaliable");

		this.key = entity.getKey();
	}
	
	public void LoadData() {
		if (this.id > -1) {
			Entity entity = LoadData(EntityName.Package, this.id);
			setEntity(entity);
		}
	}
}
